<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //  编写函数 把对象{name:'bf',age:24,from:'baidu'} 
        //  拼接成以上字符串 "http://www.xxx.com/?name=bf&age=23&from=baidu"
        var obj = {
            name: 'bf',
            age: 24,
            from: 'baidu'
        }
        function getUrl(obj) {
            var url = 'http://www.xxxxxx.com/';
            url += '?';
            // 循环对象
            for (var key in obj) {
                url += key + '=' + obj[key] + '&';
            }
            return url.slice(0, url.length-1);
        }
        console.log(getUrl(obj));
    </script>
</body>
</html>